<template>
  <e-dialog ref="dialog" :title="title" width="400px" @confirm="handleForm">
    <el-form :model="form" class="e-form">
      <el-form-item>
        <el-input
          v-model="form.name"
          placeholder="工程名称">
        </el-input>
      </el-form-item>
    </el-form>
  </e-dialog>
</template>

<script>
import eDialog from '@/components/dialog';
import {projectSpaceInsert} from '@/utils/api';
export default {
  components: {eDialog},
  data () {
    return {
      title: '新建空间',
      form: {}
    }
  },
  methods: {
    openDialog (obj) {
      if (obj) {
        this.form = Object.assign({}, obj);
        this.title = '编辑空间';
      } else {
        this.form = {};
        this.title = '新建空间';
      }
      this.$refs.dialog.openDialog();
    },
    closeDialog () {
      this.$refs.dialog.closeDialog();
    },
    handleForm () {
      const params = Object.assign({}, this.form);
      if (!params.name) {
        this.$message.warning('请填写空间名称');
        return false;
      }
      if (params.id) {
        this.$emit('editProjectSpace', params)
      } else {
        this.$emit('addProjectSpace', params)
      }
    }
  }
}
</script>